﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RBS.Common;

namespace RBS.Admin.tools
{
    public class BaseAdmin : System.Web.UI.Page
    {
        public bool IsAdminLogin()
        {
            //如果Session为Null
            if (Session[RBSKeys.SESSION_ADMIN_INFO] != null)
            {
                return true;
            }
            else
            {
                //检查Cookies
                string adminname = Utils.GetCookie("AdminName", "DTcms");
                string adminpwd = Utils.GetCookie("AdminPwd", "DTcms");
                if (adminname != "" && adminpwd != "")
                {
                    Core.BLL.manager bll = new Core.BLL.manager();
                    Core.Model.manager model = bll.GetModel(adminname, adminpwd);
                    if (model != null)
                    {
                        Session[RBSKeys.SESSION_ADMIN_INFO] = model;
                        return true;
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// 取得管理员信息
        /// </summary>
        public RBS.Core.Model.manager GetAdminInfo()
        {
            if (IsAdminLogin())
            {
                RBS.Core.Model.manager model = Session[RBSKeys.SESSION_ADMIN_INFO] as Core.Model.manager;
                if (model != null)
                {
                    return model;
                }
            }
            return null;
        }
    }
}